package com.fenfen.novel;

import android.app.Application;

import com.fenfen.novel.rest.RestClient;
import com.liulishuo.filedownloader.FileDownloader;
import com.liulishuo.filedownloader.util.FileDownloadLog;

import java.util.ArrayList;

public class MainApplication extends Application {

  private ArrayList<BaseActivity> activities = new ArrayList<>();
  private static MainApplication instance;

  @Override
  public void onCreate() {
    super.onCreate();
    RestClient.init(getApplicationContext());
    FileDownloadLog.NEED_LOG = true;
    FileDownloader.init(getApplicationContext());
  }

  public static MainApplication getInstance() {
    if (instance == null) {
      synchronized (MainApplication.class) {
        instance = new MainApplication();
      }
    }
    return instance;
  }

  public void addActivity(BaseActivity activity) {
    if (activity != null && !activities.contains(activity)) {
      activities.add(activity);
    }
  }

  public void removeActivity(BaseActivity activity) {
    if (activity != null) {
      activities.remove(activity);
    }
  }

  public ArrayList<BaseActivity> getActivities() {
    return activities;
  }
}
